package com.ruoyi.community.controller.wxApi;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.community.domain.ExerciseHistory;
import com.ruoyi.community.service.IExerciseHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动记录Controller
 *
 * @author lj
 * @date 2022-02-22
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/wx/community/eserciseHistory")
@Api(tags = {"活动记录"})
public class WxExerciseHistoryController extends BaseController
{
    @Autowired
    private IExerciseHistoryService exerciseHistoryService;

    /**
     * 查询活动记录列表
     */
    @ApiOperation(value = "查询活动记录列表")
    @GetMapping("/list")
    public TableDataInfo list(ExerciseHistory exerciseHistory)
    {
        startPage();
        List<ExerciseHistory> list = exerciseHistoryService.selectExerciseHistoryList(exerciseHistory);
        if (ObjectUtils.isEmpty(list)){
            return getNoDataTable(list);
        }
        return getDataTable(list);
    }

    /**
     * 导出活动记录列表
     */
    @ApiOperation(value = "导出活动记录列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExerciseHistory exerciseHistory)
    {
        List<ExerciseHistory> list = exerciseHistoryService.selectExerciseHistoryList(exerciseHistory);
        ExcelUtil<ExerciseHistory> util = new ExcelUtil<ExerciseHistory>(ExerciseHistory.class);
        util.exportExcel(response, list, "活动记录数据");
    }

    /**
     * 获取活动记录详细信息
     */
    @ApiOperation(value = "获取活动记录详细信息")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo( Long id)
    {
        return AjaxResult.success(exerciseHistoryService.selectExerciseHistoryById(id));
    }

    /**
     * 新增活动记录
     */
    @ApiOperation(value = "新增活动记录")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ExerciseHistory exerciseHistory)
    {
        return toAjax(exerciseHistoryService.insertExerciseHistory(exerciseHistory));
    }

    /**
     * 修改活动记录
     */
    @ApiOperation(value = "修改活动记录")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ExerciseHistory exerciseHistory)
    {
        return toAjax(exerciseHistoryService.updateExerciseHistory(exerciseHistory));
    }

    /**
     * 删除活动记录
     */
    @ApiOperation(value = "删除活动记录")
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        Long[] ids= {id};
        return toAjax(exerciseHistoryService.updateExerciseHistoryByIds(ids));
    }
}
